//
//  FtTabBar.m
//  Feast
//
//  Created by 胡光健 on 2017/8/23.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "FtTabBar.h"
@interface FtTabBar()
@property(nonatomic,weak) UIButton * leftBarButton;
@property(nonatomic,weak) UIButton * rightBarButton;
@end



@implementation FtTabBar

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.leftBarButton = [self createTabBarButton:@"lv" title:@"首页" selecteImage:self.selecteImage selecteTitle:self.selecteTitle];
        self.rightBarButton = [self createTabBarButton:@"hong" title:@"商家" selecteImage:self.selecteImage selecteTitle:self.selecteTitle];
    }
    return self;
}
-(UIButton *)createTabBarButton:(NSString *)image title:(NSString *)title selecteImage:(NSString *)selecteImage selecteTitle:(NSString *)selecteTitle {
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setBackgroundImage:HJImage(image) forState:UIControlStateNormal];
    [btn setBackgroundImage:HJImage(selecteImage) forState:UIControlStateSelected];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitle:selecteTitle forState:UIControlStateSelected];
    [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    [self bringSubviewToFront:btn];
    return btn;
}


-(void)layoutSubviews {
    [super layoutSubviews];
    
    self.leftBarButton.frame = CGRectMake(0, 0, self.frame.size.width *0.5, self.frame.size.height);
    
    self.rightBarButton.frame = CGRectMake(CGRectGetMaxX(self.leftBarButton.frame), 0, self.frame.size.width *0.5, self.frame.size.height);
}

-(void)btnClicked:(UIButton *)btn {
    if ([self.delegate respondsToSelector:@selector(tabBarButtonClicked:tabBar:)]) {
        [self.delegate tabBarButtonClicked:btn tabBar:self];
    }
}

@end
